package in.ac.dei.edrp.cms.utility;

import in.ac.dei.edrp.cms.domain.registration.prestaging.MasterTransferBean;
import in.ac.dei.edrp.cms.domain.utility.ErrorLogs;
import in.ac.dei.edrp.cms.domain.utility.StudentTracking;

import java.util.ArrayList;
import java.util.List;

import org.springframework.transaction.support.TransactionTemplate;

import com.ibatis.sqlmap.client.SqlMapClient;

public class StudentTrackingFunction {
	
	private TransactionTemplate transactionTemplate=null;
	
	public void setTransactionTemplate(TransactionTemplate transactionTemplate) {
		this.transactionTemplate = transactionTemplate;
	}

	protected SqlMapClient sqlMapClient = null;
	
    public void setSqlMapClient(SqlMapClient sqlMapClient) {
        this.sqlMapClient = sqlMapClient;
    }

    public StudentTrackingFunction(SqlMapClient sqlMapClient,TransactionTemplate transactionTemplate){
    	this.sqlMapClient=sqlMapClient;
    	this.transactionTemplate=transactionTemplate;
    }
    
    public StudentTrackingFunction(){
    	
    }
	
	/**
	 * This method returns sequence number for that semester start date and end date
	 * @param masterTransferBean
	 * @return
	 */
	public int getStdentTrackingIssue(
			StudentTracking studentTracking) {
		// TODO Auto-generated method stub
		try{
			List<StudentTracking> getCountForTrack=sqlMapClient.queryForList("studentTrackingAndLogs.getCountInStudentTracking", studentTracking);
			for(StudentTracking count:getCountForTrack){
				System.out.println("Count of student tracking "+count.getSequenceNumber());
				return count.getSequenceNumber();
			}
		}catch(Exception e){
			System.out.println("Exception getting Student Tracking:"+e.getMessage());
		}
		return 0;
	}

	
	public int batchProcessExist(ErrorLogs errorLogs) {
		// TODO Auto-generated method stub
		List<ErrorLogs> valueList=new ArrayList<ErrorLogs>();
		
		int counter=0;
		
		try{
			if(errorLogs.getBranchId()==null || errorLogs.getSpecializationId()==null){
				valueList=sqlMapClient.queryForList("studentTrackingAndLogs.getBatchCounterForProgramActivity",errorLogs);
			}
			else{
				valueList=sqlMapClient.queryForList("studentTrackingAndLogs.getBatchCounter",errorLogs);
			}					
				for(ErrorLogs processCounter:valueList){
				
					counter=processCounter.getProcessCounter();
					System.out.println("Process count="+counter);
				
				}
		
		}catch(Exception e){
			System.out.println("Process count exception is:"+e.getMessage());
		}
		
		return counter;
	}
	
	
	//To get Full Name for students
	public String getFullName(String studentFirstName,
			String studentMiddleName, String studentLastName) {
		// TODO Auto-generated method stub
		
		return studentFirstName+getName(studentMiddleName)+getName(studentLastName);
	}
	private String getName(String name) {
		// TODO Auto-generated method stub
		if(name==null || name.equalsIgnoreCase(null)){
			name="";
		}
		return name;
	}
}
